package com.cskaoyan.controller.wx_cart;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wx_cart.*;
import com.cskaoyan.bean.wx_cart.bo.FastAddBO;
import com.cskaoyan.service.wx_cart.WxCartService;
import com.cskaoyan.utils.ReflectionSetJavaBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@SuppressWarnings("all")
@RestController
@RequestMapping("wx/cart")
public class WxCartController {
    @Autowired
    WxCartService wxCartService;

    @PostMapping("checked")
    public BaseRespVo updateCartChecked(@RequestBody CartBO cartBO) {
        ReflectionSetJavaBeanUtils.setUserId(cartBO);
        List<Cart> carts = wxCartService.updateCartChecked(cartBO);
        CartListAndPara cartListAndPara = new CartListAndPara();
        cartListAndPara.setCartList(carts);
        return BaseRespVo.ok(cartListAndPara);
    }

    @PostMapping("delete")
    public BaseRespVo deleteCartInfo(@RequestBody CartBO cartBO) {
        //拿user的id
        ReflectionSetJavaBeanUtils.setUserId(cartBO);
        List<Cart> carts = wxCartService.deleteCartInfo(cartBO);
        CartListAndPara cartListAndPara = new CartListAndPara();
        cartListAndPara.setCartList(carts);
        return BaseRespVo.ok(cartListAndPara);
    }

    //需要快速生成两个表
    //101未付款
    @PostMapping("fastadd")
    public BaseRespVo fastAdd(@RequestBody FastAddBO fastAddBO) {
        ReflectionSetJavaBeanUtils.setUserId(fastAddBO);
        int code = wxCartService.fastAdd(fastAddBO);
        return BaseRespVo.ok(code);
    }

    @GetMapping("checkout")
    public BaseRespVo checkout(CheckoutBO checkoutBO) {
        ReflectionSetJavaBeanUtils.setUserId(checkoutBO);
        CheckoutVO checkout = wxCartService.checkout(checkoutBO);
        if (checkout==null){
            System.out.println("订单中有商品不存在，请重新下单");
        }
        return BaseRespVo.ok(checkout);
    }
}
